草庐IT

php - 在 Kohana 中请求::$controller

全部标签

javascript - 在 AngularJS Controller 和指令中使用 "this"而不是 "scope"

我最近在读约翰爸爸的固执己见AngularJSstyleguide并注意到他对Controller的约定:/*recommended*/functionCustomer(){varvm=this;vm.name={};vm.sendMessage=function(){};}当它在控​​制器中使用时,它工作得很好,因为你可以做这样的事情(他的例子):{{customer.name}}但是我更好奇它如何与依赖于此Controller的指令一起工作。例如,在我的Controller上使用$scope我可以做这样的事情:testModule.directive("example",funct

javascript - Angular $http 在登录后为每个请求设置 cookie

我在AngularJS中遇到$http调用问题。我创建了以下服务crApp.service('authService',function($http){varurlBase='http://192.168.xx.xx:8081';//POSTapi/login/this.login=function(credentials){return$http.post(urlBase+"/api/login",credentials);};//POSTapi/logout/this.logout=function(){return$http.post(urlBase+"/api/logout/"

javascript - node.js + 请求 => node.js + bluebird + 请求

我正在尝试了解如何使用promises编写代码。请检查我的代码。这样对吗?Node.js+请求:request(url,function(error,response,body){if(!error&&response.statusCode==200){varjsonpData=body;varjson;try{json=JSON.parse(jsonpData);}catch(e){varstartPos=jsonpData.indexOf('({');varendPos=jsonpData.indexOf('})');varjsonString=jsonpData.substrin

javascript - 缺少 CORS header 'Access-Control-Allow-Origin'

我正在尝试将webUntis(docs)API用于学校项目。现在,我只是尝试与API建立任何类型的连接。varresult;consturl='https://api.webuntis.dk/api/status';varxhr=newXMLHttpRequest();xhr.open('GET',url,true);xhr.setRequestHeader('Access-Control-Allow-Origin','*');xhr.setRequestHeader('Content-type','application/json');xhr.setRequestHeader('Ac

javascript - 在 Angular 中使用 shareReplay(1) - 仍然调用 http 请求?

我创建了一个演示(ng-run),其中有一个调用Http请求的按钮。单击按钮时,我调用此方法:publicgetData(){this._jokeService.getData().subscribe();}依次调用这个(从服务):publicgetData(){returnthis.http.get(API_ENDPOINT).pipe(shareReplay(1))}问题是每次点击-我仍然看到发起了一个新的http请求:问题:为什么shareReplay不保留响应的最后一个值?如何让我的代码仅调用一次http并为将来的订阅保留该值?编辑:solutionishere

asp.net - 访问一个asp :hiddenfield control in JavaScript

通过JavaScript访问嵌入在ASP.NETPlaceHolder控件中的ASP.NETHiddenField控件的最佳方法是什么?Visible属性在初始页面加载时设置为false,可以通过AJAX回调进行更改。这是我当前的源代码:functionAccessMyHiddenField(){varHiddenValue=document.getElementById("").value;//domythingthing.....}编辑:如何在C#中的ascx代码中设置div标签的样式?这是后面代码的描述:CssStyleCollectionHtmlControl.Style更新:

javascript - 尽管 header 正确,但 CORS Access-Control-Allow-Origin

我正在尝试在客户端上使用jQuery(1.7.1)驱动的ajax和apache服务的python(django)服务器来设置简单的跨源资源共享。根据我阅读过的所有说明,我的header设置正确,但我不断收到以下错误:XMLHttpRequestcannotloadhttp://myexternaldomain.com/get_data.Originhttp://localhost:8080isnotallowedbyAccess-Control-Allow-Origin.我正在尝试发送的header(我不确定它是否通过了浏览器)是:RequestURL:http://myexterna

javascript - 查询。 $.post 请求 .done() .fail() 避免代码重复

我有一个像这样的帖子请求$.post("test",{ajax:"true",action:""}).done(function(data){if(data=="ok"){//xxx}elseif(data=="err"){//yyy}}).fail(function(){//yyy});如果.done()方法(注释“yyy”)中的代码与fail方法(注释“yyy”)中的代码相同,如何避免post请求中的代码重复? 最佳答案 最明显和最简单的解决方案是像这样简单地进行失败回调:functionajaxFailed(){//yyy}$

javascript - 并行 API 请求的异步模块错误

我是node.js的初学者,现在我正在尝试获取一些API的结果。我正在使用异步模块(https://github.com/caolan/async)来并行处理请求,以便对其进行优化。问题是代码返回错误,每次都指向不同API调用中的不同行(“callback(err,data)”行)这是错误的:if(called)thrownewError("Callbackwasalreadycalled.");^Error:Callbackwasalreadycalled.我正在使用以下函数来请求API:functiongetData(s,apiURL,getURL,callback){varht;

javascript - angularjs:在ng-switch中从 Controller 更改父范围

所以,我可以从子Controller更改模型值,但是当子Controller在ng-switch中时它不起作用,为什么?我创建了anexample来证明它。避免这种情况的一种方法是在模型名称中使用.,例如bunnies.kills。这是错误还是功能?使用Angular1.0.6 最佳答案 使用您的代码结构,您需要在您的子Controller中更改:$scope.$parent.kills++;到$scope.$parent.$parent.kills++;解释:MainCtrl的范围是SimpleParentCtrl的父范围,但是S